//
//  OnlineOLTotalModel.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/9/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "OnlineOLTotalModel.h"

@implementation OnlineOLTotalModel


-(void)calculateCellContentSize{
    if ( self.SUMMARY_LASTTIME.length > 0) {
        self.SUMMARY_LASTTIME = [NSDateFormatter stringMonthAndHourAndMintueWithDate:[NSString stringWithFormat:@"%@" , self.SUMMARY_LASTTIME]];
    }
    if (self.contentString.length > 0) {
        self.offContentAttributedString = [[NSMutableAttributedString alloc]initWithString:self.contentString];
        self.onContentAttributedString = [[NSMutableAttributedString alloc]initWithString:self.contentString];
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:ItemHeight * 14];
        paragraphStyle.alignment = NSTextAlignmentJustified;
        //五排的高度
        
        CGSize twoFontSize = [@"张张" boundingRectWithSize:CGSizeMake(([UIScreen zj_screenWith] - ItemWidth * 48), CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LYPFONT(16) , NSParagraphStyleAttributeName : [paragraphStyle copy]} context:nil].size;
        CGFloat fiveLineHeight = twoFontSize.height;
        fiveLineHeight = fiveLineHeight * 5 + 5;
        //计算打开的高度
        self.onContentSize = [[NSString stringWithFormat:@"张张%@" , self.contentString] boundingRectWithSize:CGSizeMake(([UIScreen zj_screenWith] - ItemWidth * 48), CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LYPFONT(16) , NSParagraphStyleAttributeName : [paragraphStyle copy]} context:nil].size;

        paragraphStyle.firstLineHeadIndent = twoFontSize.width;
        [self.onContentAttributedString addAttribute:NSFontAttributeName value:LYPFONT(16) range:NSMakeRange(0, self.contentString.length)];
        [self.onContentAttributedString addAttribute:NSParagraphStyleAttributeName value:[paragraphStyle copy] range:NSMakeRange(0, self.contentString.length)];
        //判断是否大于五排
        if (fiveLineHeight >= self.onContentSize.height) {
            self.isMoreThanFiveLine = NO;
            self.offContentSize = CGSizeZero;
        }
        else{
            self.isMoreThanFiveLine = YES;
            //关闭时的高度
            NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc]init];
            [paragraphStyle1 setLineSpacing:ItemHeight * 14];
            paragraphStyle1.alignment = NSTextAlignmentJustified;
            self.offContentSize = [[NSString stringWithFormat:@"张张%@" , self.contentString] boundingRectWithSize:CGSizeMake(([UIScreen zj_screenWith] - ItemWidth * 48), fiveLineHeight + 5) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LYPFONT(16) , NSParagraphStyleAttributeName : [paragraphStyle1 copy]} context:nil].size;
            paragraphStyle1.firstLineHeadIndent = twoFontSize.width;
            paragraphStyle1.lineBreakMode = NSLineBreakByTruncatingTail;
            [self.offContentAttributedString addAttribute:NSFontAttributeName value:LYPFONT(16) range:NSMakeRange(0, self.contentString.length)];
            [self.offContentAttributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, self.contentString.length)];
        }
    }
    else{
        self.offContentAttributedString = [[NSMutableAttributedString alloc]initWithString:@""];
        self.onContentAttributedString = [[NSMutableAttributedString alloc]initWithString:@""];
    }
}

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"contentString" : @"SUMMARY"};
}



@end
